package com.ccrfid.rmc6.resource.sys;

import com.ccrfid.rmc6.appconfig.exception.pojo.AppException;
import com.ccrfid.rmc6.entity.sys.RoomManagerEntity;
import com.ccrfid.rmc6.pojo.dto.MoveInLocationDto;
import com.ccrfid.rmc6.pojo.dto.room.PersonnelInOutRecord;
import com.ccrfid.rmc6.pojo.dto.room.RoomManagerDto;
import com.ccrfid.rmc6.pojo.dto.room.RoomPrisonerDto;
import com.ccrfid.rmc6.pojo.dto.room.RoomSummaryDto;
import com.ccrfid.rmc6.service.sys.RoomService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import java.util.List;

@Path("room")
@Produces(MediaType.APPLICATION_JSON)
public class RoomResource {
    private static final Logger logger = LoggerFactory.getLogger(RoomResource.class);
    @Autowired
    private RoomService roomService;

    //获取管教民警
    @GET
    @Path("{orgId}/managers")
    public List<RoomManagerDto> getRoomManagers(@PathParam("orgId") Long roomId) {
        List<RoomManagerDto> list = roomService.getRoomManagers(roomId);
        return list;
    }

    //新增管教民警
    @POST
    @Path("manager")
    @Consumes(MediaType.APPLICATION_JSON)
    public RoomManagerDto createRoomManager(RoomManagerEntity entity) throws AppException {
        RoomManagerDto dto = roomService.createRoomManager(entity);
        return dto;
    }

    //获取某个管教民警信息
    @GET
    @Path("manager/{roomManagerId}")
    public RoomManagerDto getRoomManager(@PathParam("roomManagerId") Long roomManagerId) throws AppException {
        return roomService.getRoomManager(roomManagerId);
    }

    //更新管教民警信息
    @PUT
    @Path("manager/{roomManagerId}")
    @Consumes(MediaType.APPLICATION_JSON)
    public RoomManagerDto updateRoomManager(@PathParam("roomManagerId") Long roomManagerId,
                                            RoomManagerEntity entity) throws AppException {
        RoomManagerDto dto = roomService.updateRoomManager(roomManagerId, entity);
        return dto;
    }

    //删除管教民警
    @DELETE
    @Path("manager/{roomManagerId}")
    public Boolean deleteRoomManager(@PathParam("roomManagerId") Long roomManagerId) {
        return roomService.deleteRoomManager(roomManagerId);
    }

    //获取监室简要信息
    @GET
    @Path("{orgId}/summary")
    public RoomSummaryDto getRoomSummary(@PathParam("orgId") Long roomId) {
        return roomService.getRoomSummary(roomId);
    }

    //获取监室重点人员
    @GET
    @Path("{orgId}/prisoners/important")
    public List<RoomPrisonerDto> getImportantPrisoners(@PathParam("orgId") Long roomId) {
        return roomService.getImportantPrisoners(roomId);
    }

    //获取监室全部在押人员信息
    @GET
    @Path("{orgId}/prisoners")
    public List<RoomPrisonerDto> getAllPrisoners(@PathParam("orgId") Long roomId) {
        return roomService.getPrisoners(roomId);
    }

    //获取未在监室内的在押人员信息
    @GET
    @Path("{orgId}/prisoners/leaved")
    public List<RoomPrisonerDto> getLeavedPrisoners(@PathParam("orgId") Long roomId) {
        return roomService.getLeavedPrisoners(roomId);
    }

    //获取某个在押人员详细信息
    @GET
    @Path("prisoners/{personnelId}/detail")
    public RoomPrisonerDto getPrisonerDetail(@PathParam("personnelId") Long personnelId) {
        return roomService.getPrisonerDetail(personnelId);
    }

    //获取在押人员活动轨迹
    @GET
    @Path("prisoners/{personnelId}/activities")
    public List<MoveInLocationDto> getPersonnelActivityHistory(@PathParam("personnelId") Long personnelId,
                                                               @QueryParam("date") String dateStr) {

        return roomService.getPersonnelActivityHistory(personnelId, dateStr);
    }

    //获取监室在押人员离开监室记录
    @GET
    @Path("{orgId}/leaveRecords")
    public List<PersonnelInOutRecord> getRoomLeaveRecords(@PathParam("orgId") Long roomId,
                                                          @QueryParam("date") String dateStr) {
        return roomService.getRoomLeaveRecords2(roomId, dateStr);
    }

    //获取监室外人员进入监室记录
    @GET
    @Path("{orgId}/enterRecords")
    public List<PersonnelInOutRecord> getRoomEnterRecords(@PathParam("orgId") Long roomId,
                                                          @QueryParam("date") String dateStr) {
        return roomService.getRoomEnterRecords2(roomId, dateStr);
    }
}
